import pandas as pd
from mlxtend.preprocessing import TransactionEncoder
from mlxtend.frequent_patterns import  fpgrowth, association_rules
import load_data

file_path = "D:\数据仓库挖掘\\4.关联分析\shopping.csv"
df = load_data.DataPreprocessing(file_path)
te = TransactionEncoder()
te_ary = te.fit(df).transform(df)
df = pd.DataFrame(te_ary, columns=te.columns_)

frequent_itemsets = fpgrowth(df, min_support=0.15, use_colnames=True)
association_rules = association_rules(frequent_itemsets, metric="confidence", min_threshold=0.7)#最小置信度=0.7
print(association_rules)